<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, RoleAnnotations #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK hide #-}</span><span>
</span><span id="line-3"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-4"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-5"></span><span class="hs-comment">-- Module      :  Data.Array.Storable.Internals</span><span>
</span><span id="line-6"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow 2011</span><span>
</span><span id="line-7"></span><span class="hs-comment">-- License     :  BSD-style (see the file libraries/base/LICENSE)</span><span>
</span><span id="line-8"></span><span class="hs-comment">--</span><span>
</span><span id="line-9"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-10"></span><span class="hs-comment">-- Stability   :  experimental</span><span>
</span><span id="line-11"></span><span class="hs-comment">-- Portability :  non-portable (uses Data.Array.MArray)</span><span>
</span><span id="line-12"></span><span class="hs-comment">--</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- Actual implementation of &quot;Data.Array.Storable&quot;.</span><span>
</span><span id="line-14"></span><span class="hs-comment">--</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- @since 0.4.0.0</span><span>
</span><span id="line-16"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-17"></span><span>
</span><span id="line-18"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">Data.Array.Storable.Internals</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-19"></span><span>    </span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier">StorableArray</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">,</span><span>
</span><span id="line-20"></span><span>    </span><span class="annot"><a href="Data.Array.Storable.Internals.html#withStorableArray"><span class="hs-identifier">withStorableArray</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-21"></span><span>    </span><span class="annot"><a href="Data.Array.Storable.Internals.html#touchStorableArray"><span class="hs-identifier">touchStorableArray</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-22"></span><span>    </span><span class="annot"><a href="Data.Array.Storable.Internals.html#unsafeForeignPtrToStorableArray"><span class="hs-identifier">unsafeForeignPtrToStorableArray</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-23"></span><span>  </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-24"></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Array.Base.html"><span class="hs-identifier">Data.Array.Base</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Array.MArray.html"><span class="hs-identifier">Data.Array.MArray</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="../../base/src/Foreign.html#"><span class="hs-identifier">Foreign</span></a></span><span> </span><span class="hs-keyword">hiding</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/Foreign.Marshal.Array.html#newArray"><span class="hs-identifier">newArray</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-28"></span><span>
</span><span id="line-29"></span><span class="hs-comment">-- |The array type</span><span>
</span><span id="line-30"></span><span class="hs-keyword">data</span><span> </span><span id="StorableArray"><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-var">StorableArray</span></a></span></span><span> </span><span id="local-6989586621679054592"><span class="annot"><a href="#local-6989586621679054592"><span class="hs-identifier hs-type">i</span></a></span></span><span> </span><span id="local-6989586621679054591"><span class="annot"><a href="#local-6989586621679054591"><span class="hs-identifier hs-type">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="StorableArray"><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-var">StorableArray</span></a></span></span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="#local-6989586621679054592"><span class="hs-identifier hs-type">i</span></a></span><span> </span><span class="hs-glyph">!</span><span class="annot"><a href="#local-6989586621679054592"><span class="hs-identifier hs-type">i</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">Int</span></span><span> </span><span class="hs-glyph">!</span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.ForeignPtr.html#ForeignPtr"><span class="hs-identifier hs-type">ForeignPtr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054591"><span class="hs-identifier hs-type">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-comment">-- Both parameters have class-based invariants. See also #9220.</span><span>
</span><span id="line-32"></span><span class="hs-keyword">type</span><span> </span><span class="hs-keyword">role</span><span> </span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><span class="hs-identifier">nominal</span></span><span> </span><span class="annot"><span class="hs-identifier">nominal</span></span><span>
</span><span id="line-33"></span><span>
</span><span id="line-34"></span><span id="local-6989586621679054610"><span class="hs-keyword">instance</span><span> </span><span class="annot"><a href="../../base/src/Foreign.Storable.html#Storable"><span class="hs-identifier hs-type">Storable</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054610"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="Data.Array.Base.html#MArray"><span class="hs-identifier hs-type">MArray</span></a></span><span> </span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054610"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-35"></span><span>    </span><span id="local-6989586621679054550"><span class="annot"><span class="annottext">getBounds :: forall i. Ix i =&gt; StorableArray i e -&gt; IO (i, i)
</span><a href="Data.Array.Base.html#getBounds"><span class="hs-identifier hs-var hs-var hs-var hs-var">getBounds</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span id="local-6989586621679054548"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054548"><span class="hs-identifier hs-var">l</span></a></span></span><span> </span><span id="local-6989586621679054547"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054547"><span class="hs-identifier hs-var">u</span></a></span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(i, i) -&gt; IO (i, i)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054548"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054547"><span class="hs-identifier hs-var">u</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-36"></span><span>
</span><span id="line-37"></span><span>    </span><span id="local-6989586621679054544"><span class="annot"><span class="annottext">getNumElements :: forall i. Ix i =&gt; StorableArray i e -&gt; IO Int
</span><a href="Data.Array.Base.html#getNumElements"><span class="hs-identifier hs-var hs-var hs-var hs-var">getNumElements</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span id="local-6989586621679054542"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054542"><span class="hs-identifier hs-var">_l</span></a></span></span><span> </span><span id="local-6989586621679054541"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054541"><span class="hs-identifier hs-var">_u</span></a></span></span><span> </span><span id="local-6989586621679054540"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054540"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054540"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-38"></span><span>
</span><span id="line-39"></span><span>    </span><span id="local-6989586621679054524"><span class="annot"><span class="annottext">newArray :: forall i. Ix i =&gt; (i, i) -&gt; e -&gt; IO (StorableArray i e)
</span><a href="Data.Array.Base.html#newArray"><span class="hs-identifier hs-var hs-var hs-var hs-var">newArray</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679054522"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054522"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679054521"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054521"><span class="hs-identifier hs-var">u</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679054520"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679054520"><span class="hs-identifier hs-var">initialValue</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-40"></span><span>        </span><span id="local-6989586621679054519"><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054519"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (ForeignPtr e)
forall a. Storable a =&gt; Int -&gt; IO (ForeignPtr a)
</span><a href="../../base/src/Foreign.ForeignPtr.Imp.html#mallocForeignPtrArray"><span class="hs-identifier hs-var">mallocForeignPtrArray</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054517"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-41"></span><span>        </span><span class="annot"><span class="annottext">ForeignPtr e -&gt; (Ptr e -&gt; IO ()) -&gt; IO ()
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054519"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr e -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr e -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679054515"><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679054515"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-42"></span><span>            </span><span class="annot"><span class="annottext">[IO ()] -&gt; IO ()
forall (t :: * -&gt; *) (m :: * -&gt; *) a.
(Foldable t, Monad m) =&gt;
t (m a) -&gt; m ()
</span><a href="../../base/src/Data.Foldable.html#sequence_"><span class="hs-identifier hs-var">sequence_</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Ptr e -&gt; Int -&gt; e -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="../../base/src/Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679054515"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054512"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679054520"><span class="hs-identifier hs-var">initialValue</span></a></span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621679054512"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054512"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-special">[</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-glyph">..</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054517"><span class="hs-identifier hs-var">size</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="../../base/src/GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">]</span><span class="hs-special">]</span><span>
</span><span id="line-43"></span><span>        </span><span class="annot"><span class="annottext">StorableArray i e -&gt; IO (StorableArray i e)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">i -&gt; i -&gt; Int -&gt; ForeignPtr e -&gt; StorableArray i e
forall i e. i -&gt; i -&gt; Int -&gt; ForeignPtr e -&gt; StorableArray i e
</span><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-var">StorableArray</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054522"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054521"><span class="hs-identifier hs-var">u</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054517"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054519"><span class="hs-identifier hs-var">fp</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-44"></span><span>        </span><span class="hs-keyword">where</span><span>
</span><span id="line-45"></span><span>        </span><span id="local-6989586621679054517"><span class="annot"><span class="annottext">size :: Int
</span><a href="#local-6989586621679054517"><span class="hs-identifier hs-var hs-var">size</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(i, i) -&gt; Int
forall a. Ix a =&gt; (a, a) -&gt; Int
</span><a href="../../base/src/GHC.Ix.html#rangeSize"><span class="hs-identifier hs-var">rangeSize</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054522"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054521"><span class="hs-identifier hs-var">u</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-46"></span><span>
</span><span id="line-47"></span><span>    </span><span id="local-6989586621679054505"><span class="annot"><span class="annottext">unsafeNewArray_ :: forall i. Ix i =&gt; (i, i) -&gt; IO (StorableArray i e)
</span><a href="Data.Array.Base.html#unsafeNewArray_"><span class="hs-identifier hs-var hs-var hs-var hs-var">unsafeNewArray_</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679054503"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054503"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679054502"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054502"><span class="hs-identifier hs-var">u</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-48"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679054500"><span class="annot"><span class="annottext">n :: Int
</span><a href="#local-6989586621679054500"><span class="hs-identifier hs-var hs-var">n</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(i, i) -&gt; Int
forall a. Ix a =&gt; (a, a) -&gt; Int
</span><a href="../../base/src/GHC.Ix.html#rangeSize"><span class="hs-identifier hs-var">rangeSize</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054503"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054502"><span class="hs-identifier hs-var">u</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span>        </span><span id="local-6989586621679054499"><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054499"><span class="hs-identifier hs-var">fp</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO (ForeignPtr e)
forall a. Storable a =&gt; Int -&gt; IO (ForeignPtr a)
</span><a href="../../base/src/Foreign.ForeignPtr.Imp.html#mallocForeignPtrArray"><span class="hs-identifier hs-var">mallocForeignPtrArray</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054500"><span class="hs-identifier hs-var">n</span></a></span><span>
</span><span id="line-50"></span><span>        </span><span class="annot"><span class="annottext">StorableArray i e -&gt; IO (StorableArray i e)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">i -&gt; i -&gt; Int -&gt; ForeignPtr e -&gt; StorableArray i e
forall i e. i -&gt; i -&gt; Int -&gt; ForeignPtr e -&gt; StorableArray i e
</span><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-var">StorableArray</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054503"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054502"><span class="hs-identifier hs-var">u</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054500"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054499"><span class="hs-identifier hs-var">fp</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-51"></span><span>
</span><span id="line-52"></span><span>    </span><span id="local-6989586621679054495"><span class="annot"><span class="annottext">newArray_ :: forall i. Ix i =&gt; (i, i) -&gt; IO (StorableArray i e)
</span><a href="Data.Array.Base.html#newArray_"><span class="hs-identifier hs-var hs-var hs-var hs-var">newArray_</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(i, i) -&gt; IO (StorableArray i e)
forall (a :: * -&gt; * -&gt; *) e (m :: * -&gt; *) i.
(MArray a e m, Ix i) =&gt;
(i, i) -&gt; m (a i e)
</span><a href="Data.Array.Base.html#unsafeNewArray_"><span class="hs-identifier hs-var">unsafeNewArray_</span></a></span><span>
</span><span id="line-53"></span><span>
</span><span id="line-54"></span><span>    </span><span id="local-6989586621679054491"><span class="annot"><span class="annottext">unsafeRead :: forall i. Ix i =&gt; StorableArray i e -&gt; Int -&gt; IO e
</span><a href="Data.Array.Base.html#unsafeRead"><span class="hs-identifier hs-var hs-var hs-var hs-var">unsafeRead</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">i
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679054489"><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054489"><span class="hs-identifier hs-var">fp</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679054488"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054488"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-55"></span><span>        </span><span class="annot"><span class="annottext">ForeignPtr e -&gt; (Ptr e -&gt; IO e) -&gt; IO e
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054489"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr e -&gt; IO e) -&gt; IO e) -&gt; (Ptr e -&gt; IO e) -&gt; IO e
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679054487"><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679054487"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; Int -&gt; IO e
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="../../base/src/Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679054487"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054488"><span class="hs-identifier hs-var">i</span></a></span><span>
</span><span id="line-56"></span><span>
</span><span id="line-57"></span><span>    </span><span id="local-6989586621679054483"><span class="annot"><span class="annottext">unsafeWrite :: forall i. Ix i =&gt; StorableArray i e -&gt; Int -&gt; e -&gt; IO ()
</span><a href="Data.Array.Base.html#unsafeWrite"><span class="hs-identifier hs-var hs-var hs-var hs-var">unsafeWrite</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">i
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679054481"><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054481"><span class="hs-identifier hs-var">fp</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679054480"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054480"><span class="hs-identifier hs-var">i</span></a></span></span><span> </span><span id="local-6989586621679054479"><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679054479"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-58"></span><span>        </span><span class="annot"><span class="annottext">ForeignPtr e -&gt; (Ptr e -&gt; IO ()) -&gt; IO ()
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054481"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr e -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr e -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679054478"><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679054478"><span class="hs-identifier hs-var">a</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; Int -&gt; e -&gt; IO ()
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; a -&gt; IO ()
</span><a href="../../base/src/Foreign.Storable.html#pokeElemOff"><span class="hs-identifier hs-var">pokeElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679054478"><span class="hs-identifier hs-var">a</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679054480"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">e
</span><a href="#local-6989586621679054479"><span class="hs-identifier hs-var">e</span></a></span></span><span>
</span><span id="line-59"></span><span>
</span><span id="line-60"></span><span class="hs-comment">-- |The pointer to the array contents is obtained by 'withStorableArray'.</span><span>
</span><span id="line-61"></span><span class="hs-comment">-- The idea is similar to 'ForeignPtr' (used internally here).</span><span>
</span><span id="line-62"></span><span class="hs-comment">-- The pointer should be used only during execution of the 'IO' action</span><span>
</span><span id="line-63"></span><span class="hs-comment">-- retured by the function passed as argument to 'withStorableArray'.</span><span>
</span><span id="line-64"></span><span id="local-6989586621679054583"><span id="local-6989586621679054584"><span id="local-6989586621679054585"><span class="annot"><a href="Data.Array.Storable.Internals.html#withStorableArray"><span class="hs-identifier hs-type">withStorableArray</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054585"><span class="hs-identifier hs-type">i</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054584"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054584"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679054583"><span class="hs-identifier hs-type">a</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="annot"><a href="#local-6989586621679054583"><span class="hs-identifier hs-type">a</span></a></span></span></span></span><span>
</span><span id="line-65"></span><span id="withStorableArray"><span class="annot"><span class="annottext">withStorableArray :: forall i e a. StorableArray i e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="Data.Array.Storable.Internals.html#withStorableArray"><span class="hs-identifier hs-var hs-var">withStorableArray</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">i
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679054477"><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054477"><span class="hs-identifier hs-var">fp</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679054476"><span class="annot"><span class="annottext">Ptr e -&gt; IO a
</span><a href="#local-6989586621679054476"><span class="hs-identifier hs-var">f</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
forall a b. ForeignPtr a -&gt; (Ptr a -&gt; IO b) -&gt; IO b
</span><a href="../../base/src/GHC.ForeignPtr.html#withForeignPtr"><span class="hs-identifier hs-var">withForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054477"><span class="hs-identifier hs-var">fp</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; IO a
</span><a href="#local-6989586621679054476"><span class="hs-identifier hs-var">f</span></a></span><span>
</span><span id="line-66"></span><span>
</span><span id="line-67"></span><span class="hs-comment">-- |If you want to use it afterwards, ensure that you</span><span>
</span><span id="line-68"></span><span class="hs-comment">-- 'touchStorableArray' after the last use of the pointer,</span><span>
</span><span id="line-69"></span><span class="hs-comment">-- so the array is not freed too early.</span><span>
</span><span id="line-70"></span><span id="local-6989586621679054578"><span id="local-6989586621679054579"><span class="annot"><a href="Data.Array.Storable.Internals.html#touchStorableArray"><span class="hs-identifier hs-type">touchStorableArray</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054579"><span class="hs-identifier hs-type">i</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054578"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span></span><span>
</span><span id="line-71"></span><span id="touchStorableArray"><span class="annot"><span class="annottext">touchStorableArray :: forall i e. StorableArray i e -&gt; IO ()
</span><a href="Data.Array.Storable.Internals.html#touchStorableArray"><span class="hs-identifier hs-var hs-var">touchStorableArray</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">i
</span><span class="hs-identifier">_</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621679054475"><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054475"><span class="hs-identifier hs-var">fp</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">ForeignPtr e -&gt; IO ()
forall a. ForeignPtr a -&gt; IO ()
</span><a href="../../base/src/GHC.ForeignPtr.html#touchForeignPtr"><span class="hs-identifier hs-var">touchForeignPtr</span></a></span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054475"><span class="hs-identifier hs-var">fp</span></a></span><span>
</span><span id="line-72"></span><span>
</span><span id="line-73"></span><span class="hs-comment">-- |Construct a 'StorableArray' from an arbitrary 'ForeignPtr'.  It is</span><span>
</span><span id="line-74"></span><span class="hs-comment">-- the caller's responsibility to ensure that the 'ForeignPtr' points to</span><span>
</span><span id="line-75"></span><span class="hs-comment">-- an area of memory sufficient for the specified bounds.</span><span>
</span><span id="line-76"></span><span id="local-6989586621679054573"><span id="local-6989586621679054574"><span class="annot"><a href="Data.Array.Storable.Internals.html#unsafeForeignPtrToStorableArray"><span class="hs-identifier hs-type">unsafeForeignPtrToStorableArray</span></a></span><span>
</span><span id="line-77"></span><span>   </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Ix.html#Ix"><span class="hs-identifier hs-type">Ix</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054574"><span class="hs-identifier hs-type">i</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="../../base/src/GHC.ForeignPtr.html#ForeignPtr"><span class="hs-identifier hs-type">ForeignPtr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054573"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="#local-6989586621679054574"><span class="hs-identifier hs-type">i</span></a></span><span class="hs-special">,</span><span class="annot"><a href="#local-6989586621679054574"><span class="hs-identifier hs-type">i</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">IO</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-type">StorableArray</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054574"><span class="hs-identifier hs-type">i</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679054573"><span class="hs-identifier hs-type">e</span></a></span><span class="hs-special">)</span></span></span><span>
</span><span id="line-78"></span><span id="unsafeForeignPtrToStorableArray"><span class="annot"><span class="annottext">unsafeForeignPtrToStorableArray :: forall i e.
Ix i =&gt;
ForeignPtr e -&gt; (i, i) -&gt; IO (StorableArray i e)
</span><a href="Data.Array.Storable.Internals.html#unsafeForeignPtrToStorableArray"><span class="hs-identifier hs-var hs-var">unsafeForeignPtrToStorableArray</span></a></span></span><span> </span><span id="local-6989586621679054470"><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054470"><span class="hs-identifier hs-var">p</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679054469"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054469"><span class="hs-identifier hs-var">l</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679054468"><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054468"><span class="hs-identifier hs-var">u</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-79"></span><span>   </span><span class="annot"><span class="annottext">StorableArray i e -&gt; IO (StorableArray i e)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">i -&gt; i -&gt; Int -&gt; ForeignPtr e -&gt; StorableArray i e
forall i e. i -&gt; i -&gt; Int -&gt; ForeignPtr e -&gt; StorableArray i e
</span><a href="Data.Array.Storable.Internals.html#StorableArray"><span class="hs-identifier hs-var">StorableArray</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054469"><span class="hs-identifier hs-var">l</span></a></span><span> </span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054468"><span class="hs-identifier hs-var">u</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(i, i) -&gt; Int
forall a. Ix a =&gt; (a, a) -&gt; Int
</span><a href="../../base/src/GHC.Ix.html#rangeSize"><span class="hs-identifier hs-var">rangeSize</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054469"><span class="hs-identifier hs-var">l</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">i
</span><a href="#local-6989586621679054468"><span class="hs-identifier hs-var">u</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">ForeignPtr e
</span><a href="#local-6989586621679054470"><span class="hs-identifier hs-var">p</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-80"></span><span>
</span><span id="line-81"></span></pre></body></html>